package com.vrv.vap.baseline.service.impl;

import com.vrv.vap.baseline.entity.ActGeBytearray;
import com.vrv.vap.baseline.mapper.ActGeBytearrayMapper;
import com.vrv.vap.baseline.service.AbstractExcelExportService;
import com.vrv.vap.baseline.util.FileOperationUtil;
import com.vrv.vap.baseline.config.ExcelTemplateConfig;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Service
public class ActGeBytearrayExportService extends AbstractExcelExportService<ActGeBytearray> {
    private static final String key = "act_ge_bytearray";
    private final ActGeBytearrayMapper actGeBytearrayMapper;

    public ActGeBytearrayExportService(FileOperationUtil fileOperationUtil, ExcelTemplateConfig excelTemplateConfig, ActGeBytearrayMapper actGeBytearrayMapper) {
        super(fileOperationUtil, excelTemplateConfig, key);
        this.actGeBytearrayMapper = actGeBytearrayMapper;
    }

    @Override
    protected List<ActGeBytearray> getAllData() {
        return actGeBytearrayMapper.selectAll();
    }

    @Override
    protected void processData(List<ActGeBytearray> dataList, String format) throws IOException {
        for (ActGeBytearray bytearray : dataList) {
            // 处理bytes字段
            byte[] bytes = bytearray.getBytes();
            if (bytes != null && bytes.length > 0) {
                String fileName = bytearray.getId() + "_bytes.bin";
                File file = fileOperationUtil.createFile(fileName, key, format);
                fileOperationUtil.writeBytesToFile(file, bytes);
                bytearray.setBytes(null);
            }
        }
    }

    @Override
    protected Class<ActGeBytearray> getEntityClass() {
        return ActGeBytearray.class;
    }
}